﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using WSMP.WSMPDataAccess;
using WSMP.Helpers;

namespace WSMP.Administration.UserManagement
{
    public partial class UserList : System.Web.UI.Page
    {
        DataAccess dAL;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                dAL = new DataAccess();
                DataTable dt = dAL.getDataUsingSP("GetAllUsers");
                UserGridView.GridRowDataBound += new UserControls.Grid.RowDataBound(UserGridView_RowDataBound);
                foreach (DataColumn col in dt.Columns)
                {
                    //Declare the bound field and allocate memory for the bound field.
                    TemplateField bfield = new TemplateField();

                    //Initalize the DataField value.

                    bfield.HeaderTemplate = new GridViewTemplate(ListItemType.Header, col.ColumnName);

                    //Initialize the HeaderText field value.
                    if (col.ColumnName.Equals("ProfileCreated"))
                        bfield.ItemTemplate = new GridViewTemplate(ListItemType.Item, col.ColumnName, true);
                    else
                        bfield.ItemTemplate = new GridViewTemplate(ListItemType.Item, col.ColumnName);

                    //Add the newly created bound field to the GridView.
                    UserGridView.GrdView.Columns.Add(bfield);
                    if (col.ColumnName == "UserId")
                        bfield.Visible = false;

                }
                UserGridView.DataSource = dt;
                UserGridView.GrdView.DataBind();
                ViewState["data"] = UserGridView.GrdView.DataSource;
                UserGridView.NewButtonTitle = "New User";
                UserGridView.NewButtonHref = "~/Account/Register.aspx";

                // new Inc_GridView.RowDataBound(Inc_GridView1_GridRowDataBound); 
            }
        }



        protected void UserGridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType.Equals(DataControlRowType.DataRow))
            {
                TableCell cell = e.Row.Cells[2];
                if (cell.Text.Equals("0"))
                { }
                else { }
                var data = ((System.Data.DataRowView)(e.Row.DataItem)).Row.ItemArray;
                if (data[3].ToString().Equals("0") && data[2].ToString().Equals("0"))
                {


                }
            }
        }

        DataTable UserDataTable()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("UserId");
            dt.Columns.Add("UserName");
            dt.Columns.Add("UserType");
            dt.Columns.Add("ProfileCreated");
            DataRow dr = dt.NewRow();
            dr["UserId"] = "1";
            dr["UserName"] = "Administrator";
            dr["UserType"] = "Admin";
            dr["ProfileCreated"] = "False";
            dt.Rows.Add(dr);
            dr = dt.NewRow();
            dr["UserId"] = "2";
            dr["UserName"] = "Vishnnu";
            dr["UserType"] = "Student";
            dr["ProfileCreated"] = "False";
            dt.Rows.Add(dr);
            return dt;
        }
    }
}